home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
UTILITIE
/
CONVERSI
/
1396.ZIP
/
STRIP.ARC
/
STRIP301.BAS
< prev
Wrap
BASIC Source File
|
1988-06-04
|
11KB
|
297 lines
'
' STRIP301.BAS -- Program to strip leading characters from any text file.
' ~~~~~~~~~~~~ -------------------------------------------------------
' Author - Chip Morrow
' 40 Valley View Dr.
' Newark, OH 43055
'
' Version 3.01 finished June 4, 1988 - released as Shareware.
' This program is not copyrighted, I ask only that you
' acknowledge it if you use any of my code in your own
' programs. Thanks!
'
' *************************************************
' * Go to error handling routine if one occurs. *
' *************************************************
'
5 on error goto 3000
' **********************************************************************
' * Line 6 is ERL check for the existence of the configuration file. *
' **********************************************************************
'
6 defint a-z
open "STRIP.CNF" for input as #1
input #1,STRIPNUM
if STRIPNUM < 1 or STRIPNUM > 3 then goto cnf.error
for x = 1 to STRIPNUM
input #1,strip.temp$
if x = 1 then strip1$ = strip.temp$
if x = 2 then strip2$ = strip.temp$
if x = 3 then strip3$ = strip.temp$
next
close
' *******************************************************
' * Check for parameters entered on the command line. *
' *******************************************************
'
If Command$ = "*" goto command.line.cnf
If Command$ = "h" or Command$ = "H" goto 1000
If Command$ = "?" goto 1000
If Command$ = "help" or Command$ = "HELP" goto 1000
If Command$ = "" then gosub 4000 : goto 10
gosub 3010 : f$ = COMMAND1$ : new$ = COMMAND2$ : GOTO 12
10 '
' ********************************************************************
' * No parameters were entered on the command line. Get filenames. *
' ********************************************************************
'
Defint a-z : cls
locate 20,1 : Line input "Enter SOURCE filename --> ",F$
locate 20,1 : print space$(70)
if F$ = "" goto 1000
locate 20,1 : Line input "Save changes to --------> ",NEW$
cls
12 '
' ***************************************************************
' * Line 12 is GOTO line in case the variables are already set. *
' * Last check for no filenames. *
' ***************************************************************
'
gosub 4000
If len(f$) < 1 then goto 1000
if len(new$) < 1 then gosub 2000
name f$ as f$
15 '
' *****************************************************************
' * Line 15 is a RESUME line for error #58 (File already exists). *
' * Normal file opening starts here. *
' *****************************************************************
'
Open f$ for input as #1
total$ = str$(lof(1))
Open new$ for output as #2
x$ = "SOURCE file <" + F$ + "> ----" + total$
locate 3,1 : print x$
x$ = "OBJECT file <" + NEW$ + "> ---- "
locate 4,1 : print x$
linenum = 1
30 '
' ********************************************************************
' * Code re-written here for version 3.00. Input by line instead of *
' * byte-for-byte as it was previously. MUCH faster execution. *
' ********************************************************************
'
line input #1,TEXT$
linenum = linenum + 1
goto 30
35 linenum = (linenum - 1)
close 1
open f$ for input as #1
counter = 1
while not eof(1)
gosub file.input
counter = counter + 1
wend
goto 37
file.input:
line input #1,text$
locate 6,1 : print "Converting line number"counter
if left$(text$,1) = STRIP1$ or _
left$(text$,1) = STRIP2$ and stripnum > 1 or _
left$(text$,1) = STRIP3$ and stripnum > 2 then gosub 40
print #2,text$
return
37 '
' ***********************************************************************
' * End of conversion. Close files, check length of file just created, *
' * print the info, and exit to DOS. *
' ***********************************************************************
'
close
open new$ as #1 len = 1
new.total$ = str$(lof(1))
close
x$ = "OBJECT file <" + NEW$ + "> ----" + new.total$
locate 4,1 : print space$(78)
locate 4,1 : print x$ : locate 6,1 : print space$(78)
locate 6,1 : print linenum "lines processed." : end
40 '
' ***************************************************************
' * Subroutine to strip the offending characters one at a time. *
' ***************************************************************
'
y = len(text$)
if y < 1 then return
new.text$ = mid$(text$,2,(y-1))
text$ = new.text$
if left$(text$,1) = STRIP1$ or _
left$(text$,1) = STRIP2$ and stripnum > 1 or _
left$(text$,1) = STRIP3$ and stripnum > 2 then goto 40
return
1000 '
' **********************************
' * Routine to display help info. *
' **********************************
'
cls
Print _
"STRIP.COM version 3.01 by Chip Morrow - June 4, 1988" CHR$(13) CHR$(13) _
"Delete leading characters from lines within text files." CHR$(13) CHR$(13) _
"Usage:" CHR$(13) CHR$(13)_
"STRIP source.fil object.fil - or -" CHR$(13) _
"STRIP source.fil - or -" CHR$(13) _
"STRIP * to create new configuration file - or -" CHR$(13) _
"STRIP ? to display this message" CHR$(13) CHR$(13)
end
2000 '
' ********************************************************************
' * Routine to default the object file name to the source file name *
' * with the extension .FIX. *
' ********************************************************************
'
DEFAULTF$ = ""
CASE = 0
FOR X = 1 TO LEN(F$)
IF POINTER = 1 GOTO 2050
MID$(F$,X,1) = CHR$(ASC(MID$(F$,X,1)))
ZZ = ASC(MID$(F$,X,1))
IF ZZ > 64 and ZZ < 90 then case = 1
IF ZZ = 46 then goto 2043
DEFAULTF$ = DEFAULTF$ + CHR$(ZZ)
GOTO 2050
2043 POINTER = 1
GOTO 2050
2050 NEXT X
IF CASE = 0 then FIX$ = ".fix"
IF CASE = 1 then FIX$ = ".FIX"
DEFAULTF$ = DEFAULTF$ + FIX$ : NEW$ = DEFAULTF$ : return
3000 '
' *********************************************************
' * The main error handler. All errors pass this way... *
' *********************************************************
'
IF ERR = 52 and ERL = 35 then resume cnf.error
IF ERR = 52 and ERL = 15 then print "Incomplete OBJECT file name." : end
IF ERR = 53 and ERL = 6 then resume create
IF ERR = 53 then print "SOURCE file <"F$"> not found." : end
IF ERR = 55 and ERL = 15 then print "SOURCE and OBJECT file names cannot be identical." : end
IF ERR = 58 then resume 15
IF ERR = 62 then resume 35
IF ERR = 64 then print "Invalid filespec." : end
IF ERR = 76 then print "Invalid path/filepec" : end
PRINT "An untrapped error has occurred."
print
print "Most common causes:"
print
print "- Invalid path name for the source or object file."
print : print "- Disk door open when attempting to read/write to floppy."
print : print "- Out of disk space."
print : print "Error number"ERR"in line number"ERL"."
END
3010 '
' ***********************************************
' * Routine to handle command line parameters. *
' ***********************************************
'
POINTER = 0
CONVERT$ = COMMAND$
COMMAND1$ = ""
COMMAND2$ = ""
FOR X = 1 TO LEN(COMMAND$)
MID$(CONVERT$,X,1) = CHR$(ASC(MID$(CONVERT$,X,1)))
ZZ = ASC(MID$(CONVERT$,X,1))
IF X = 1 THEN GOTO 3030
IF ZZ = 32 and pointer = 1 then pointer = 2 : goto 3050
IF ZZ = 44 and pointer = 1 then pointer = 2 : goto 3050
IF ZZ = 32 then pointer = 1 : goto 3050
IF ZZ = 44 then pointer = 1 : goto 3050
IF POINTER = 1 THEN GOTO 3020
IF POINTER = 2 THEN GOTO 3050
COMMAND1$ = COMMAND1$ + CHR$(ZZ)
GOTO 3050
3020 COMMAND2$ = COMMAND2$ + CHR$(ZZ)
GOTO 3050
3030 COMMAND1$ = COMMAND1$ + CHR$(ZZ)
3050 NEXT X
if command2$ = "" then gosub 2000
RETURN
4000 locate 1,1 : print "STRIP - V 3.01 by Chip Morrow" : return
create:
'
' ********************************************************
' * STRIP.CNF was not found. Create a new one, or exit. *
' ********************************************************
'
close
print "STRIP.CNF not found on default drive." : print
print "Press <ESC> to exit, any other key to create configuration file..."
create1:
create$ = inkey$
if create$ = CHR$(27) then end
if create$ = "" then goto create1
close : cls
x$ = "Number of characters to strip (1-3)? "
print x$
create2:
line1$ = inkey$
if line1$ = "1" or line1$ = "2" or line1$ = "3" goto create3
if line1$ = "" goto create2
goto create2
create3:
locate 1,(len(x$)+1) : print line1$
open "STRIP.CNF" for output as #1
print #1,line1$
strip.chars = val(line1$)
line.num = 2
for x = 1 to strip.chars
create4:
strip.char$ = inkey$
char.num = line.num - 1
x$ = "Enter character #" + str$(char.num) + " to strip? "
locate line.num,1 : print x$
while strip.char$ = "" : goto create4 : wend
strip.val = asc(strip.char$)
locate line.num,(len(x$)+1) : print "ASCII code -" strip.val
print #1,chr$(34) + strip.char$ + chr$(34)
line.num = line.num + 1
next
close
locate 6,1 : print "Configuration file created."
end
cnf.error:
'
' ***********************************************
' * Error trap for an invalid STRIP.CNF file. *
' ***********************************************
'
print "Configuration file STRIP.CNF is invalid."
print
command.line.cnf:
print "Press any key to create new STRIP.CNF file or <ESC> to exit..."
goto create1